package logic

import (
	"context"
	"mall/model/redis"
	"strconv"

	"mall/mallrpc/internal/svc"
	"mall/mallrpc/mallrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserLikeListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserLikeListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserLikeListLogic {
	return &UserLikeListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserLikeListLogic) UserLikeList(in *mallrpc.UserLikeListRequest) (*mallrpc.UserLikeListResponse, error) {
	// todo: add your logic here and delete this line
	scores := redis.Client.ZRevRangeWithScores("productLike", 0, 9)

	var score []*mallrpc.LikeList

	for _, m := range scores.Val() {
		list := &mallrpc.LikeList{
			Name: m.Member.(string),
			Like: strconv.Itoa(int(m.Score)),
		}
		score = append(score, list)
	}

	return &mallrpc.UserLikeListResponse{List: score}, nil
}
